package com.siriframe.security.util;

import com.siriframe.security.dao.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class UserCheckUtils {

    @Autowired
    private UserMapper userMapper;

    private static UserCheckUtils userCheckUtils;

    @PostConstruct
    public void init(){
        userCheckUtils = this;
        userCheckUtils.userMapper = this.userMapper;
    }

    public static boolean checkUsernameExist(String username){

        boolean flag = false;

        Map map = new ConcurrentHashMap();
        map.put("username", username);
        List list = userCheckUtils.userMapper.selectByMap(map);
        if(list.isEmpty()){
            flag = true;
        }
        return flag;
    }
}
